package top.chmin.project.cloud.sys.code.info;

import top.chmin.project.cloud.sys.dict.data.DictDataCondition;
import top.chmin.project.cloud.sys.dict.data.DictData;

import java.util.stream.Collectors;
import java.util.Map;
import java.util.List;
import top.chmin.project.cloud.common.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import cn.hutool.core.bean.BeanUtil;



/**
 * chmin
 * 2024-01-26 13:58:12
 * cloud-code
 */
@Service
@Transactional
public class CodeInfoService {

    @Resource
    CodeInfoPlugin plugin;

    public int save(CodeInfoSaveRest.P p) {
        plugin.checkSave(p);
        CodeInfo codeInfo = BeanUtil.toBean(p, CodeInfo.class);
        plugin.beforeSave(codeInfo);
        int result = codeInfo.forInsert().execute();
        plugin.afterSave(p, codeInfo, result);
        return result;
    }

    public CodeInfoSelectRest.R select(CodeInfoSelectRest.P p) {
        plugin.checkSelect(p);
        CodeInfoCondition c = CodeInfoCondition.forSelect().id().eq(p.getId());
        plugin.beforeSelect(p, c);
        CodeInfoSelectRest.R r = c.selectFirst(CodeInfoSelectRest.R.class);
        plugin.afterSelect(p, r);
        return r;
    }

    public int update(CodeInfoUpdateRest.P p) {
        plugin.checkUpdate(p);
        CodeInfo codeInfo = BeanUtil.toBean(p, CodeInfo.class);
        plugin.beforeUpdate(codeInfo);
        int result = codeInfo.forUpdate().id().eq().execute();
        plugin.afterUpdate(p, codeInfo, result);
        return result;
    }

    public int delete(CodeInfoDeleteRest.P p) {
        plugin.checkDelete(p);
        CodeInfo codeInfo = BeanUtil.toBean(p, CodeInfo.class);
        plugin.beforeDelete(codeInfo);
        int result = codeInfo.forDelete().id().eq().execute();
        plugin.afterDelete(p, codeInfo, result);
        return result;
    }

    public Page<CodeInfoPageRest.R> page(CodeInfoPageRest.P p) {
        plugin.checkPage(p);
        CodeInfoCondition c = CodeInfoCondition.forSelect();
        c = p.isDesc() ? c.id().desc() : c.id().asc();
        plugin.beforePage(p, c);
        Page<CodeInfoPageRest.R> r = c.selectPage(CodeInfoPageRest.R.class);
        /*###########auto#start###########*/
        /*###########auto##end############*/
        /* append $serviceRelateAppender$ */
        /*###########auto#start###########*/
        /*###########auto##end############*/
        /* append $serviceDictAppender$ */
        plugin.afterPage(p, r);
        return r;
    }
    /* append $serviceSelectOptionMethodAppender$ */
}
